#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
int main()
{
	int y = 0;
	int m = 0;
	while (scanf("%d%d", &y, &m) != EOF)
	{
		switch (m)
		{
		case 2:
			if (y % 4 == 0 && y % 100 != 0 || y % 400 == 0 && m ==2)
			{
				printf("29");
			}
			else
			{
				printf("28");
			}
			break;
		case 4:
		case 6:
		case 9:
		case 11:
			printf("30");
			break;
		default:
			printf("31");
			break;
		}
	}
	return 0;
}